﻿<style>
	#showZtreDiv{
		width: 100px;
		height:100px;
	}

	#loadfile{
		position: absolute;
		z-index: 1;
		opacity: 0;
		-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
		filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
		top: 0;
	}
	.layui-input-loadfile{
		position: relative;
	}
	.layui-inline{
		height: 40px;
	}

</style>
<span class="layui-breadcrumb">
    <a href="javascript:void(0)">当前位置:</a>
    <a href="javascript:void(0)">行方系统菜单 > </a>
    <a href="javascript:void(0)"><cite>部门管理</cite> </a>
</span>
<div class="layui-form-item layui-form-item-top">

	<button class="layui-btn-tan" id="addType">
		<i class="layui-icon">&#xe608;</i> 添加
	</button>

</div>
<form class="layui-form" action="${basePath}merchant/dept/getDeptlistPage" method="post" type="0" name="deptForm" id="deptForm">
	<div class="searchbox" id="searchbox">

		<input type="text" name="searchConent"  value="${pd.keywords}" lay-verify="title" autocomplete="off" placeholder="请输入关键字" class="layui-input">
		<input type="button" value="查询" onclick="searchs();" class="layui-btn layui-btn-red"/>

	<div class="layui-inline" style="  float: right; margin-right: 15px;margin-top: -5px;">
<input type="button" value="查看部门层级" onclick="viewDept()" style="margin-right: 20px;"  class="layui-btn layui-btn-red"/>
</div>
</div>




<div class="levTable">
	<table id="simple-table" class="table table-striped table-bordered table-hover" >
		<thead>
		<tr>
			<th style="width:50px;">序号</th>
			<!--<th>部门编号</th>-->
			<th>部门名称</th>
			<th>上级部门</th>
			<th style="width: 100px;">操作</th>
		</tr>
		</thead>
		<tbody>
		<#list deptList?if_exists as var>
			<tr>
				<td style="width: 30px;">${var_index+1}</td>
				<!--<td>${var.deptNo}</td>-->
				<td>${var.deptName}</td>
				<td>${var.parentName}</td>
				<td >

					<a class="layui-icon"  onclick="editDept('${var.deptId}');" title="修改">&#xe642;</a>

				<a class="layui-icon" onclick="deleteDept('${var.deptId}');" title="删除">&#xe640;</a>

			</td>
			</tr>
		</#list>
		</tbody>
	</table>
</div>
<#include "/common/page.html" />
</form>
<script type="text/javascript" src="${basePath}static\js\ajaxfileupload.js"></script>
<link type="text/css" rel="stylesheet" href="${basePath}plugins/zTree/3.5.1/zTreeStyle/zTreeStyle.css"/>
<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.excheck.js"></script>
<script type="text/javascript">
	var rooturl = "${basePath}merchant/dept/getDeptlistPage";
	function viewDept() {
		layer.open({
			type: 2,
			title : '查看部门层级关系',
			content: '${basePath}merchant/dept/toDeptTree',

			area: [ '450px', '400px'],
			btn: ['关闭'],
			yes : function(index, layero) {
				layer.close(index);
			},
			end : function() {
			}
		});
	}
	$("#addType").click(function(){
		var _url = $("form:eq(0)").attr("action");
		layer.open({
			type: 2,
			title : '添加部门',//刘佳 17-9-15-14:31
			content: "${basePath}merchant/dept/toDeptEdit",
			area: [ '650px', '400px' ],
			btn: ['确定', '取消'],
			yes : function(index, layero) {
				var iframeWin = window[layero.find('iframe')[0]['name']];

				iframeWin.save();
			},
			no : function(index) {
				//layer.close(index);
			},
			end : function() {
//                setTimeout("self.location.reload()", 100);
				reLoadPage(rooturl);
			}
		});
	});
	//检索
	function searchs() {
		_GLOBE_DATA("reLoadPageParam")(_GLOBE_DATA("createURL")(rooturl,"searchbox"));
	}

	function uploadInput1() {
		$("#uploadInput").val($("#loadfile").val());
	}
	// 修改
	function editDept(deptId) {
		var _url = $("form:eq(0)").attr("action");
		layer.open({
			type : 2,//此处以iframe举例
			title : '部门信息编辑',
			area: [ '650px', '400px' ],
			content : '${basePath}merchant/dept/toDeptEdit?deptId='+deptId,
			btn : [ '保存', '关闭' ], //只是为了演示
			yes : function(index, layero) {
				var iframeWin = window[layero.find('iframe')[0]['name']];
				iframeWin.save1();
			},
			no : function(index) {
				layer.close(index);
			},
			end : function() {
				//setTimeout("self.location.reload()", 100);
				reLoadPage(rooturl);
			}
		});
	}
	//删除
	function deleteDept(deptId) {

		layer.confirm('确认要删除吗？', {
			btn: ['确定', '取消']
		}, function(index, layero){
			$.ajax({
				url : '${basePath}merchant/dept/deleteDept',
				data : {
					deptId : deptId
				},
				type : "POST",
				success : function(data) {
					if (data.status == 'success') {
						layer.alert(data.msg,function(index){
							var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
							parent.layer.close(index1);
							parent.layer.close(index);
							reLoadPage(rooturl);
						});
					} else {
						layer.alert(data.msg);
					}
				}
			});
		});
	}

	//导出模板
	function exportExcel() {
		window.location.href = "${basePath}merchant/dept/getExPort";
	}

	//上传报表
	function uploadImport() {
		if ($.trim($("#loadfile").val()) == "") {
			layer.alert("请选择上传文件！");
			return;
		}
		$.ajaxFileUpload(
				{
					url: '${basePath}merchant/dept/readdeptExcel',            //需要链接到服务器地址
					secureuri: false,
					fileElementId: 'loadfile',                     //文件选择框的id属性
					// dataType: 'json',                          //服务器返回的格式，可以是json
					success: function (data, status) {
						debugger;//相当于java中try语句块的用法
						if (data.status == 'success') {
							layer.alert("上传成功");
							reLoadPage(rooturl);
						} else {
							layer.alert(data.msg);
						}
					},
					error: function (data, status, e)            //相当于java中catch语句块的用法
					{
						//$("#complate").show().text("上传失败！").css("color","#cc0033");
					}
				}
		);
	}
</script>
